package com.dehui.traders.ui.viewmodle;

import android.content.Context;
import android.databinding.ObservableArrayList;
import android.databinding.ObservableField;
import android.databinding.ObservableList;
import android.widget.TextView;

import com.dehui.traders.R;
import com.dehui.traders.adapter.RankListAdapter;
import com.dehui.traders.bean.RankBean;
import com.dehui.traders.utils.SimulatedDataManager;
import com.dehui.traders.widgets.BaseViewHolder;
import com.dehui.traders.widgets.CommonAdapter;

import java.util.ArrayList;
import java.util.List;

import me.goldze.mvvmhabit.base.BaseViewModel;
import me.goldze.mvvmhabit.binding.command.BindingCommand;
import rx.functions.Action0;

/**
 * Created by hqq on 18.4.2.
 */

public class RankMarketViewModel extends BaseViewModel{

    public ObservableList<RankBean> rankListObservabel = new ObservableArrayList<>();

    public RankListAdapter rankListAdapter = new RankListAdapter(context,rankListObservabel, R.layout.list_item_rank_market);

    public ObservableField<CommonAdapter> rankadapterObservable = new ObservableField<>(rankListAdapter);

    public ObservableList<String> nameListObservabel = new ObservableArrayList<>();

    public RankMarketViewModel(Context context) {
        super(context);
        initData();
    }

    private void initData() {
        ArrayList<RankBean> rankList = SimulatedDataManager.getRankList();
        List<String> nameList = SimulatedDataManager.getRankNames();

        rankListObservabel.addAll(rankList);
        nameListObservabel.addAll(nameList);
    }

     private CommonAdapter<String> nameAdapter = new CommonAdapter<String>(context, nameListObservabel, R.layout.list_item_rank_bottom_market) {
        @Override
        public void convert(BaseViewHolder helper, String item, int position) {
            TextView tvTitle = helper.getView(R.id.tv_title);
            tvTitle.setText(item);
        }
    };

    public ObservableField<CommonAdapter> nameadapterObservable= new ObservableField<>(nameAdapter);

}
